using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace View.Instant
{
    public class LoadingView : View
    {
        private Transform mImgLoading;
        private float mAddRotate = 0;
        private float mStartTimer = 0;
        private float mEndTimer = 5;
        private bool mIsUpdate = false;
        public override void OnLoad()
        {
            base.OnLoad();
            mImgLoading = transform.Find("Image");
        }

        private void Update(float timer)
        {
            if (mIsUpdate)
            {
                mAddRotate += Time.deltaTime * -300f;
                mImgLoading.transform.localEulerAngles = new Vector3(0, 0, mAddRotate);

                mStartTimer += Time.deltaTime;
                if (mStartTimer >= mEndTimer)
                {
                    mIsUpdate = false;
                    mStartTimer = 0;
                    UIManager.Instance.OnCloseLoading();
                }
            }
        }
        
        public override void OnShow(params object[] args)
        {
            base.OnShow();
            mIsUpdate = true;
            Utils.OnUpdate += Update;
        }

        public override void OnClose(params object[] args)
        {
            base.OnClose();
            Utils.OnUpdate -= Update;
            mIsUpdate = false;
            mStartTimer = 0;
        }
    }
}

